﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using _1242026_1242133.DTO;
using _1242026_1242133.DAO;
using _1242026_1242133.BUS;
using System.Windows.Forms;

namespace _1242026_1242133
{
    public partial class frmQuanLyLoaiPhong : Form
    {
        private void LoadDanhSachLoaiPhong()
        {
            LoaiPhongBUS LoaiPhongBus = new LoaiPhongBUS();
            DataTable data = LoaiPhongBus.LoadDanhSachLoaiPhong();
            dgLoaiPhong.DataSource = data;
        }
        public frmQuanLyLoaiPhong()
        {
            InitializeComponent();
            LoadDanhSachLoaiPhong();
        }

        private bool KiemTraNhapLoaiPhong()
        {
            if (txtMaLoaiPhong.Text == "" || txtTenloaiPhong.Text == "" ||txtGiaLoaiPhong.Text == ""|| txtSoKhachToiDa.Text == ""|| txtTyLePhuThu.Text == "")
            {
                MessageBox.Show("Chưa Nhập Đủ Thông Tin", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            return true;
        }
        private void btThemLoaiPhong_Click(object sender, EventArgs e)
        {
            if (KiemTraNhapLoaiPhong())
            {
                LoaiPhongDTO LoaiPhongDto = new LoaiPhongDTO(txtMaLoaiPhong.Text, txtTenloaiPhong.Text, int.Parse(txtGiaLoaiPhong.Text), int.Parse(txtSoKhachToiDa.Text), float.Parse(txtTyLePhuThu.Text));
                LoaiPhongBUS LoaiPhongBus = new LoaiPhongBUS();
                DataTable data = LoaiPhongBus.ThemLoaiPhong(LoaiPhongDto);
                DataRow dr = data.Rows[0];
                MessageBox.Show(dr["ErrMsg"].ToString(), "Thông Báo");
                LoaiPhongBus.LoadDanhSachLoaiPhong();
            }
        }
    }
}
